package com.pxene.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;

public class CookieTask extends Configuration implements Tool {

	public void setConf(Configuration conf) {
		// TODO Auto-generated method stub

	}

	public Configuration getConf() {
		// TODO Auto-generated method stub
		return null;
	}

	public int run(String[] args) throws Exception {
		// conf参数
		Configuration conf = new Configuration();
		conf.set("mapreduce.job.queuename", args[0]);
		Job job = Job.getInstance(conf);
		FileSystem fs = FileSystem.get(conf);
		// 入口
		job.setJarByClass(CookieTask.class);
		// mapreduce
		job.setMapperClass(CookieMap.class);

		job.setNumReduceTasks(0);

		// 输入输出路径
		FileInputFormat.addInputPath(job, new Path(args[1]));
		Path out = new Path(args[2]);
		FileOutputFormat.setOutputPath(job, out);

		// 输入输出格式
		job.setInputFormatClass(SequenceFileInputFormat.class);

		job.setMapOutputValueClass(Text.class);
		job.setMapOutputValueClass(Text.class);
		// 保护性代码
		if (fs.exists(out)) {
			fs.delete(out, true);
		}
		// 执行
		return job.waitForCompletion(true) ? 0 : 1;
	}

}
